<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">

<title>class Struct - RDoc Documentation</title>


<script src="./js/navigation.js" defer></script>
<script src="./js/search.js" defer></script>
<script src="./js/search_index.js" defer></script>
<script src="./js/searcher.js" defer></script>
<script src="./js/darkfish.js" defer></script>

<script src="./js/jquery-3.2.0.min.js"></script>

<script src="./js/vue.min.js"></script>
<script src="./js/js.cookie.min.js"></script>

<link href="./css/fonts.css" rel="stylesheet">
<link id='rdoccss' href="./css/rdoc.css" rel="stylesheet">
<link href="./css/carbon17.css" rel="stylesheet">

<script type="text/javascript">
  var rdoc_rel_prefix = "./";
  var index_rel_prefix = "./";
  var darkModeCsseHref = "./css/rdoc-dm.css"
  var defaultModeCssHref = "./css/rdoc.css"
  // var cssDarkmode = Cookies.get('darkmode');
  
  if( Cookies.get("darkmode") == "true") {
	$('#rdoccss').attr("href", darkModeCsseHref);
}

//  https://cssdeck.com/blog/simple-jquery-stylesheet-switcher/

document.write('<style type="text/css">body{display:none}</style>');

</script>


</head>
<body id="top" role="document" class="class">
  <!-- this is class.html -->

  <div id='actionbar' >
    <div class='wrapper mdiv'>
      <ul class='grids g0'></ul>
    </div> 
    <!-- VERSION HEADER for 3.3.0-preview2 NOT FOUND -->
  </div> <!-- end action bar -->

  <div class='wrapper hdiv'>

    


    <nav id='vapp' role="navigation">
    <div id="project-navigation">
      <div id="home-section" role="region" title="Quick navigation" class="nav-section">
  <h2><a href="./index.html" rel="home">Home</a></h2>

  <div id="table-of-contents-navigation"  >
    <a href="./table_of_contents.html#pages">Pages</a>
    <a href="./table_of_contents.html#classes">Classes</a>
    <a href="./table_of_contents.html#methods">Methods</a>
  </div>
</div>

      <div id="search-section" role="search" class="project-section initially-hidden">
  <form action="#" method="get" accept-charset="utf-8">
    <div id="search-field-wrapper">
      <input id="search-field" role="combobox" aria-label="Search"
             aria-autocomplete="list" aria-controls="search-results"
             type="text" name="search" placeholder="Search" spellcheck="false"
             title="Type to search, Up and Down to navigate, Enter to load">
    </div>

    <ul id="search-results" aria-label="Search Results"
        aria-busy="false" aria-expanded="false"
        aria-atomic="false" class="initially-hidden"></ul>
  </form>
</div>

    </div>


    
<div class="nav-section">
  <h3>Table of Contents</h3>

  <ul class="link-list" role="directory">
    <li><a href="#class-Struct-label-What-27s+Here">What’s Here</a>
    <li><a href="#class-Struct-label-Methods+for+Creating+a+Struct+Subclass">Methods for Creating a Struct Subclass</a>
    <li><a href="#class-Struct-label-Methods+for+Querying">Methods for Querying</a>
    <li><a href="#class-Struct-label-Methods+for+Comparing">Methods for Comparing</a>
    <li><a href="#class-Struct-label-Methods+for+Fetching">Methods for Fetching</a>
    <li><a href="#class-Struct-label-Methods+for+Assigning">Methods for Assigning</a>
    <li><a href="#class-Struct-label-Methods+for+Iterating">Methods for Iterating</a>
    <li><a href="#class-Struct-label-Methods+for+Converting">Methods for Converting</a>
  </ul>
</div>


    <button id='toggleThing' @click="toggleNav()" >Show/hide navigation</button>
    <div :class="isOpen ? 'block' : 'hidden' " id='toggleMe'>
      <div id="class-metadata">
        
        
<div id="parent-class-section" class="nav-section">
  <h3>Parent</h3>

  <p class="link"><a href="Object.html">Object</a>
</div>

        
<div id="includes-section" class="nav-section">
  <h3>Included Modules</h3>

  <ul class="link-list">
    <li><a class="include" href="Enumerable.html">Enumerable</a>
  </ul>
</div>

        
        
<!-- Method Quickref -->
<div id="method-list-section" class="nav-section">
  <h3>Methods</h3>

  <ul class="link-list" role="directory">
    <li ><a href="#method-c-keyword_init-3F">::keyword_init?</a>
    <li ><a href="#method-c-members">::members</a>
    <li ><a href="#method-c-new">::new</a>
    <li ><a href="#method-i-3D-3D">#==</a>
    <li ><a href="#method-i-5B-5D">#[]</a>
    <li ><a href="#method-i-5B-5D-3D">#[]=</a>
    <li ><a href="#method-i-deconstruct">#deconstruct</a>
    <li ><a href="#method-i-deconstruct_keys">#deconstruct_keys</a>
    <li ><a href="#method-i-dig">#dig</a>
    <li ><a href="#method-i-each">#each</a>
    <li ><a href="#method-i-each_pair">#each_pair</a>
    <li ><a href="#method-i-eql-3F">#eql?</a>
    <li ><a href="#method-i-filter">#filter</a>
    <li ><a href="#method-i-hash">#hash</a>
    <li ><a href="#method-i-inspect">#inspect</a>
    <li ><a href="#method-i-length">#length</a>
    <li ><a href="#method-i-members">#members</a>
    <li ><a href="#method-i-select">#select</a>
    <li ><a href="#method-i-size">#size</a>
    <li ><a href="#method-i-to_a">#to_a</a>
    <li ><a href="#method-i-to_h">#to_h</a>
    <li ><a href="#method-i-to_s">#to_s</a>
    <li ><a href="#method-i-values">#values</a>
    <li ><a href="#method-i-values_at">#values_at</a>
  </ul>
</div>

      </div>
     </div>
    </nav>


    <div id='extraz'><div class='adzbox-index'  >
      
     </div>         
    </div>

    <main role="main" aria-labelledby="class-Struct">
    <h1 id="class-Struct" class="class">
      class Struct
    </h1>

    <section class="description">
    
<p>Class Struct provides a convenient way to create a simple class that can store and fetch values.</p>

<p>This example creates a subclass of <code>Struct</code>, <code>Struct::Customer</code>; the first argument, a string, is the name of the subclass; the other arguments, symbols, determine the <em>members</em> of the new subclass.</p>

<pre class="ruby"><span class="ruby-constant">Customer</span> = <span class="ruby-constant">Struct</span>.<span class="ruby-identifier">new</span>(<span class="ruby-string">&#39;Customer&#39;</span>, <span class="ruby-value">:name</span>, <span class="ruby-value">:address</span>, <span class="ruby-value">:zip</span>)
<span class="ruby-constant">Customer</span>.<span class="ruby-identifier">name</span>       <span class="ruby-comment"># =&gt; &quot;Struct::Customer&quot;</span>
<span class="ruby-constant">Customer</span>.<span class="ruby-identifier">class</span>      <span class="ruby-comment"># =&gt; Class</span>
<span class="ruby-constant">Customer</span>.<span class="ruby-identifier">superclass</span> <span class="ruby-comment"># =&gt; Struct</span>
</pre>

<p>Corresponding to each member are two methods, a writer and a reader, that store and fetch values:</p>

<pre class="ruby"><span class="ruby-identifier">methods</span> = <span class="ruby-constant">Customer</span>.<span class="ruby-identifier">instance_methods</span> <span class="ruby-keyword">false</span>
<span class="ruby-identifier">methods</span> <span class="ruby-comment"># =&gt; [:zip, :address=, :zip=, :address, :name, :name=]</span>
</pre>

<p>An instance of the subclass may be created, and its members assigned values, via method <code>::new</code>:</p>

<pre class="ruby"><span class="ruby-identifier">joe</span> = <span class="ruby-constant">Customer</span>.<span class="ruby-identifier">new</span>(<span class="ruby-string">&quot;Joe Smith&quot;</span>, <span class="ruby-string">&quot;123 Maple, Anytown NC&quot;</span>, <span class="ruby-value">12345</span>)
<span class="ruby-identifier">joe</span> <span class="ruby-comment"># =&gt; #&lt;struct Struct::Customer name=&quot;Joe Smith&quot;, address=&quot;123 Maple, Anytown NC&quot;, zip=12345&gt;</span>
</pre>

<p>The member values may be managed thus:</p>

<pre class="ruby"><span class="ruby-identifier">joe</span>.<span class="ruby-identifier">name</span>    <span class="ruby-comment"># =&gt; &quot;Joe Smith&quot;</span>
<span class="ruby-identifier">joe</span>.<span class="ruby-identifier">name</span> = <span class="ruby-string">&#39;Joseph Smith&#39;</span>
<span class="ruby-identifier">joe</span>.<span class="ruby-identifier">name</span>    <span class="ruby-comment"># =&gt; &quot;Joseph Smith&quot;</span>
</pre>

<p>And thus; note that member name may be expressed as either a string or a symbol:</p>

<pre class="ruby"><span class="ruby-identifier">joe</span>[<span class="ruby-value">:name</span>]  <span class="ruby-comment"># =&gt; &quot;Joseph Smith&quot;</span>
<span class="ruby-identifier">joe</span>[<span class="ruby-value">:name</span>] = <span class="ruby-string">&#39;Joseph Smith, Jr.&#39;</span>
<span class="ruby-identifier">joe</span>[<span class="ruby-string">&#39;name&#39;</span>] <span class="ruby-comment"># =&gt; &quot;Joseph Smith, Jr.&quot;</span>
</pre>

<p>See <a href="Struct.html#method-c-new"><code>Struct::new</code></a>.</p>

<h2 id="class-Struct-label-What-27s+Here">What’s Here<span><a href="#class-Struct-label-What-27s+Here">&para;</a> <a href="#top">&uarr;</a></span></h2>

<p>First, what’s elsewhere. Class Struct:</p>
<ul><li>
<p>Inherits from <a href="Object.html#class-Object-label-What-27s+Here">class Object</a>.</p>
</li><li>
<p>Includes <a href="Enumerable.html#module-Enumerable-label-What-27s+Here">module Enumerable</a>, which provides dozens of additional methods.</p>
</li></ul>

<p>See also <a href="Data.html"><code>Data</code></a>, which is a somewhat similar, but stricter concept for defining immutable value objects.</p>

<p>Here, class Struct provides methods that are useful for:</p>
<ul><li>
<p><a href="Struct.html#class-Struct-label-Methods+for+Creating+a+Struct+Subclass">Creating a Struct Subclass</a></p>
</li><li>
<p><a href="Struct.html#class-Struct-label-Methods+for+Querying">Querying</a></p>
</li><li>
<p><a href="Struct.html#class-Struct-label-Methods+for+Comparing">Comparing</a></p>
</li><li>
<p><a href="Struct.html#class-Struct-label-Methods+for+Fetching">Fetching</a></p>
</li><li>
<p><a href="Struct.html#class-Struct-label-Methods+for+Assigning">Assigning</a></p>
</li><li>
<p><a href="Struct.html#class-Struct-label-Methods+for+Iterating">Iterating</a></p>
</li><li>
<p><a href="Struct.html#class-Struct-label-Methods+for+Converting">Converting</a></p>
</li></ul>

<h3 id="class-Struct-label-Methods+for+Creating+a+Struct+Subclass">Methods for Creating a <a href="Struct.html"><code>Struct</code></a> Subclass<span><a href="#class-Struct-label-Methods+for+Creating+a+Struct+Subclass">&para;</a> <a href="#top">&uarr;</a></span></h3>
<ul><li>
<p><a href="Struct.html#method-c-new"><code>::new</code></a>: Returns a new subclass of Struct.</p>
</li></ul>

<h3 id="class-Struct-label-Methods+for+Querying">Methods for Querying<span><a href="#class-Struct-label-Methods+for+Querying">&para;</a> <a href="#top">&uarr;</a></span></h3>
<ul><li>
<p><a href="Struct.html#method-i-hash"><code>hash</code></a>: Returns the integer hash code.</p>
</li><li>
<p><a href="Struct.html#method-i-length"><code>length</code></a>, <a href="Struct.html#method-i-size"><code>size</code></a>: Returns the number of members.</p>
</li></ul>

<h3 id="class-Struct-label-Methods+for+Comparing">Methods for Comparing<span><a href="#class-Struct-label-Methods+for+Comparing">&para;</a> <a href="#top">&uarr;</a></span></h3>
<ul><li>
<p><a href="Struct.html#method-i-3D-3D"><code>==</code></a>: Returns whether a given object is equal to <code>self</code>, using <code>==</code> to compare member values.</p>
</li><li>
<p><a href="Struct.html#method-i-eql-3F"><code>eql?</code></a>: Returns whether a given object is equal to <code>self</code>, using <code>eql?</code> to compare member values.</p>
</li></ul>

<h3 id="class-Struct-label-Methods+for+Fetching">Methods for Fetching<span><a href="#class-Struct-label-Methods+for+Fetching">&para;</a> <a href="#top">&uarr;</a></span></h3>
<ul><li>
<p><a href="Struct.html#method-i-5B-5D"><code>[]</code></a>: Returns the value associated with a given member name.</p>
</li><li>
<p><a href="Struct.html#method-i-to_a"><code>to_a</code></a>, <a href="Struct.html#method-i-values"><code>values</code></a>, <a href="Struct.html#method-i-deconstruct"><code>deconstruct</code></a>: Returns the member values in <code>self</code> as an array.</p>
</li><li>
<p><a href="Struct.html#method-i-deconstruct_keys"><code>deconstruct_keys</code></a>: Returns a hash of the name/value pairs for given member names.</p>
</li><li>
<p><a href="Struct.html#method-i-dig"><code>dig</code></a>: Returns the object in nested objects that is specified by a given member name and additional arguments.</p>
</li><li>
<p><a href="Struct.html#method-i-members"><code>members</code></a>: Returns an array of the member names.</p>
</li><li>
<p><a href="Struct.html#method-i-select"><code>select</code></a>, <a href="Struct.html#method-i-filter"><code>filter</code></a>: Returns an array of member values from <code>self</code>, as selected by the given block.</p>
</li><li>
<p><a href="Struct.html#method-i-values_at"><code>values_at</code></a>: Returns an array containing values for given member names.</p>
</li></ul>

<h3 id="class-Struct-label-Methods+for+Assigning">Methods for Assigning<span><a href="#class-Struct-label-Methods+for+Assigning">&para;</a> <a href="#top">&uarr;</a></span></h3>
<ul><li>
<p><a href="Struct.html#method-i-5B-5D-3D"><code>[]=</code></a>: Assigns a given value to a given member name.</p>
</li></ul>

<h3 id="class-Struct-label-Methods+for+Iterating">Methods for Iterating<span><a href="#class-Struct-label-Methods+for+Iterating">&para;</a> <a href="#top">&uarr;</a></span></h3>
<ul><li>
<p><a href="Struct.html#method-i-each"><code>each</code></a>: Calls a given block with each member name.</p>
</li><li>
<p><a href="Struct.html#method-i-each_pair"><code>each_pair</code></a>: Calls a given block with each member name/value pair.</p>
</li></ul>

<h3 id="class-Struct-label-Methods+for+Converting">Methods for Converting<span><a href="#class-Struct-label-Methods+for+Converting">&para;</a> <a href="#top">&uarr;</a></span></h3>
<ul><li>
<p><a href="Struct.html#method-i-inspect"><code>inspect</code></a>, <a href="Struct.html#method-i-to_s"><code>to_s</code></a>: Returns a string representation of <code>self</code>.</p>
</li><li>
<p><a href="Struct.html#method-i-to_h"><code>to_h</code></a>: Returns a hash of the member name/value pairs in <code>self</code>.</p>
</li></ul>

    </section>

      <section id="5Buntitled-5D" class="documentation-section">





                <section id="public-class-5Buntitled-5D-method-details" class="method-section">
                <header>
                <h3>Public Class Methods</h3>
                </header>

                  <div id="method-c-keyword_init-3F" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          StructClass::keyword_init? &rarr; true or falsy value
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns <code>true</code> if the class was initialized with <code>keyword_init: true</code>. Otherwise returns <code>nil</code> or <code>false</code>.</p>

<p>Examples:</p>

<pre class="ruby"><span class="ruby-constant">Foo</span> = <span class="ruby-constant">Struct</span>.<span class="ruby-identifier">new</span>(<span class="ruby-value">:a</span>)
<span class="ruby-constant">Foo</span>.<span class="ruby-identifier">keyword_init?</span> <span class="ruby-comment"># =&gt; nil</span>
<span class="ruby-constant">Bar</span> = <span class="ruby-constant">Struct</span>.<span class="ruby-identifier">new</span>(<span class="ruby-value">:a</span>, <span class="ruby-value">keyword_init:</span> <span class="ruby-keyword">true</span>)
<span class="ruby-constant">Bar</span>.<span class="ruby-identifier">keyword_init?</span> <span class="ruby-comment"># =&gt; true</span>
<span class="ruby-constant">Baz</span> = <span class="ruby-constant">Struct</span>.<span class="ruby-identifier">new</span>(<span class="ruby-value">:a</span>, <span class="ruby-value">keyword_init:</span> <span class="ruby-keyword">false</span>)
<span class="ruby-constant">Baz</span>.<span class="ruby-identifier">keyword_init?</span> <span class="ruby-comment"># =&gt; false</span>
</pre>

                              <div class="method-source-code" id="keyword_init-3F-source">
            <pre>static VALUE
rb_struct_s_keyword_init_p(VALUE obj)
{
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-c-members" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          StructClass::members &rarr; array_of_symbols
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns the member names of the <a href="Struct.html"><code>Struct</code></a> descendant as an array:</p>

<pre class="ruby"><span class="ruby-constant">Customer</span> = <span class="ruby-constant">Struct</span>.<span class="ruby-identifier">new</span>(<span class="ruby-value">:name</span>, <span class="ruby-value">:address</span>, <span class="ruby-value">:zip</span>)
<span class="ruby-constant">Customer</span>.<span class="ruby-identifier">members</span> <span class="ruby-comment"># =&gt; [:name, :address, :zip]</span>
</pre>

                              <div class="method-source-code" id="members-source">
            <pre>static VALUE
rb_struct_s_members_m(VALUE klass)
{
    VALUE members = rb_struct_s_members(klass);

    return rb_ary_dup(members);
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-c-new" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          new(*member_names, keyword_init: nil){|Struct_subclass| ... } &rarr; Struct_subclass
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>
                      <div class="method-heading">
                        <span class="method-callseq">
                          new(class_name, *member_names, keyword_init: nil){|Struct_subclass| ... } &rarr; Struct_subclass
                              </span>
                            </div>
                      <div class="method-heading">
                        <span class="method-callseq">
                          new(*member_names) &rarr; Struct_subclass_instance
                              </span>
                            </div>
                      <div class="method-heading">
                        <span class="method-callseq">
                          new(**member_names) &rarr; Struct_subclass_instance
                              </span>
                            </div>

                            <div class="method-description">
                              <p><code>Struct.new</code> returns a new subclass of <code>Struct</code>.  The new subclass:</p>
<ul><li>
<p>May be anonymous, or may have the name given by <code>class_name</code>.</p>
</li><li>
<p>May have members as given by <code>member_names</code>.</p>
</li><li>
<p>May have initialization via ordinary arguments, or via keyword arguments</p>
</li></ul>

<p>The new subclass has its own method <code>::new</code>; thus:</p>

<pre class="ruby"><span class="ruby-constant">Foo</span> = <span class="ruby-constant">Struct</span>.<span class="ruby-identifier">new</span>(<span class="ruby-string">&#39;Foo&#39;</span>, <span class="ruby-value">:foo</span>, <span class="ruby-value">:bar</span>) <span class="ruby-comment"># =&gt; Struct::Foo</span>
<span class="ruby-identifier">f</span> = <span class="ruby-constant">Foo</span>.<span class="ruby-identifier">new</span>(<span class="ruby-value">0</span>, <span class="ruby-value">1</span>)                   <span class="ruby-comment"># =&gt; #&lt;struct Struct::Foo foo=0, bar=1&gt;</span>
</pre>

<p><strong>Class Name</strong></p>

<p>With string argument <code>class_name</code>, returns a new subclass of <code>Struct</code> named <code>Struct::<em>class_name</em></code>:</p>

<pre class="ruby"><span class="ruby-constant">Foo</span> = <span class="ruby-constant">Struct</span>.<span class="ruby-identifier">new</span>(<span class="ruby-string">&#39;Foo&#39;</span>, <span class="ruby-value">:foo</span>, <span class="ruby-value">:bar</span>) <span class="ruby-comment"># =&gt; Struct::Foo</span>
<span class="ruby-constant">Foo</span>.<span class="ruby-identifier">name</span>                            <span class="ruby-comment"># =&gt; &quot;Struct::Foo&quot;</span>
<span class="ruby-constant">Foo</span>.<span class="ruby-identifier">superclass</span>                      <span class="ruby-comment"># =&gt; Struct</span>
</pre>

<p>Without string argument <code>class_name</code>, returns a new anonymous subclass of <code>Struct</code>:</p>

<pre class="ruby"><span class="ruby-constant">Struct</span>.<span class="ruby-identifier">new</span>(<span class="ruby-value">:foo</span>, <span class="ruby-value">:bar</span>).<span class="ruby-identifier">name</span> <span class="ruby-comment"># =&gt; nil</span>
</pre>

<p><strong>Block</strong></p>

<p>With a block given, the created subclass is yielded to the block:</p>

<pre class="ruby"><span class="ruby-constant">Customer</span> = <span class="ruby-constant">Struct</span>.<span class="ruby-identifier">new</span>(<span class="ruby-string">&#39;Customer&#39;</span>, <span class="ruby-value">:name</span>, <span class="ruby-value">:address</span>) <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">new_class</span><span class="ruby-operator">|</span>
  <span class="ruby-identifier">p</span> <span class="ruby-node">&quot;The new subclass is #{new_class}&quot;</span>
  <span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">greeting</span>
    <span class="ruby-node">&quot;Hello #{name} at #{address}&quot;</span>
  <span class="ruby-keyword">end</span>
<span class="ruby-keyword">end</span>           <span class="ruby-comment"># =&gt; Struct::Customer</span>
<span class="ruby-identifier">dave</span> = <span class="ruby-constant">Customer</span>.<span class="ruby-identifier">new</span>(<span class="ruby-string">&#39;Dave&#39;</span>, <span class="ruby-string">&#39;123 Main&#39;</span>)
<span class="ruby-identifier">dave</span> <span class="ruby-comment"># =&gt;     #&lt;struct Struct::Customer name=&quot;Dave&quot;, address=&quot;123 Main&quot;&gt;</span>
<span class="ruby-identifier">dave</span>.<span class="ruby-identifier">greeting</span> <span class="ruby-comment"># =&gt; &quot;Hello Dave at 123 Main&quot;</span>
</pre>

<p>Output, from <code>Struct.new</code>:</p>

<pre class="ruby"><span class="ruby-string">&quot;The new subclass is Struct::Customer&quot;</span>
</pre>

<p><strong>Member Names</strong></p>

<p><a href="Symbol.html"><code>Symbol</code></a> arguments <code>member_names</code> determines the members of the new subclass:</p>

<pre class="ruby"><span class="ruby-constant">Struct</span>.<span class="ruby-identifier">new</span>(<span class="ruby-value">:foo</span>, <span class="ruby-value">:bar</span>).<span class="ruby-identifier">members</span>        <span class="ruby-comment"># =&gt; [:foo, :bar]</span>
<span class="ruby-constant">Struct</span>.<span class="ruby-identifier">new</span>(<span class="ruby-string">&#39;Foo&#39;</span>, <span class="ruby-value">:foo</span>, <span class="ruby-value">:bar</span>).<span class="ruby-identifier">members</span> <span class="ruby-comment"># =&gt; [:foo, :bar]</span>
</pre>

<p>The new subclass has instance methods corresponding to <code>member_names</code>:</p>

<pre class="ruby"><span class="ruby-constant">Foo</span> = <span class="ruby-constant">Struct</span>.<span class="ruby-identifier">new</span>(<span class="ruby-string">&#39;Foo&#39;</span>, <span class="ruby-value">:foo</span>, <span class="ruby-value">:bar</span>)
<span class="ruby-constant">Foo</span>.<span class="ruby-identifier">instance_methods</span>(<span class="ruby-keyword">false</span>) <span class="ruby-comment"># =&gt; [:foo, :bar, :foo=, :bar=]</span>
<span class="ruby-identifier">f</span> = <span class="ruby-constant">Foo</span>.<span class="ruby-identifier">new</span>                 <span class="ruby-comment"># =&gt; #&lt;struct Struct::Foo foo=nil, bar=nil&gt;</span>
<span class="ruby-identifier">f</span>.<span class="ruby-identifier">foo</span>                       <span class="ruby-comment"># =&gt; nil</span>
<span class="ruby-identifier">f</span>.<span class="ruby-identifier">foo</span> = <span class="ruby-value">0</span>                   <span class="ruby-comment"># =&gt; 0</span>
<span class="ruby-identifier">f</span>.<span class="ruby-identifier">bar</span>                       <span class="ruby-comment"># =&gt; nil</span>
<span class="ruby-identifier">f</span>.<span class="ruby-identifier">bar</span> = <span class="ruby-value">1</span>                   <span class="ruby-comment"># =&gt; 1</span>
<span class="ruby-identifier">f</span>                           <span class="ruby-comment"># =&gt; #&lt;struct Struct::Foo foo=0, bar=1&gt;</span>
</pre>

<p><strong>Singleton Methods</strong></p>

<p>A subclass returned by <a href="Struct.html#method-c-new"><code>Struct.new</code></a> has these singleton methods:</p>
<ul><li>
<p>Method <code>::new </code> creates an instance of the subclass:</p>

<pre class="ruby"><span class="ruby-constant">Foo</span>.<span class="ruby-identifier">new</span>          <span class="ruby-comment"># =&gt; #&lt;struct Struct::Foo foo=nil, bar=nil&gt;</span>
<span class="ruby-constant">Foo</span>.<span class="ruby-identifier">new</span>(<span class="ruby-value">0</span>)       <span class="ruby-comment"># =&gt; #&lt;struct Struct::Foo foo=0, bar=nil&gt;</span>
<span class="ruby-constant">Foo</span>.<span class="ruby-identifier">new</span>(<span class="ruby-value">0</span>, <span class="ruby-value">1</span>)    <span class="ruby-comment"># =&gt; #&lt;struct Struct::Foo foo=0, bar=1&gt;</span>
<span class="ruby-constant">Foo</span>.<span class="ruby-identifier">new</span>(<span class="ruby-value">0</span>, <span class="ruby-value">1</span>, <span class="ruby-value">2</span>) <span class="ruby-comment"># Raises ArgumentError: struct size differs</span>

<span class="ruby-comment"># Initialization with keyword arguments:</span>
<span class="ruby-constant">Foo</span>.<span class="ruby-identifier">new</span>(<span class="ruby-value">foo:</span> <span class="ruby-value">0</span>)         <span class="ruby-comment"># =&gt; #&lt;struct Struct::Foo foo=0, bar=nil&gt;</span>
<span class="ruby-constant">Foo</span>.<span class="ruby-identifier">new</span>(<span class="ruby-value">foo:</span> <span class="ruby-value">0</span>, <span class="ruby-value">bar:</span> <span class="ruby-value">1</span>) <span class="ruby-comment"># =&gt; #&lt;struct Struct::Foo foo=0, bar=1&gt;</span>
<span class="ruby-constant">Foo</span>.<span class="ruby-identifier">new</span>(<span class="ruby-value">foo:</span> <span class="ruby-value">0</span>, <span class="ruby-value">bar:</span> <span class="ruby-value">1</span>, <span class="ruby-value">baz:</span> <span class="ruby-value">2</span>)
<span class="ruby-comment"># Raises ArgumentError: unknown keywords: baz</span>
</pre>
</li><li>
<p>Method <code>:inspect</code> returns a string representation of the subclass:</p>

<pre class="ruby"><span class="ruby-constant">Foo</span>.<span class="ruby-identifier">inspect</span>
<span class="ruby-comment"># =&gt; &quot;Struct::Foo&quot;</span>
</pre>
</li><li>
<p>Method <code>::members</code> returns an array of the member names:</p>

<pre class="ruby"><span class="ruby-constant">Foo</span>.<span class="ruby-identifier">members</span> <span class="ruby-comment"># =&gt; [:foo, :bar]</span>
</pre>
</li></ul>

<p><strong>Keyword Argument</strong></p>

<p>By default, the arguments for initializing an instance of the new subclass can be both positional and keyword arguments.</p>

<p>Optional keyword argument <code>keyword_init:</code> allows to force only one type of arguments to be accepted:</p>

<pre class="ruby"><span class="ruby-constant">KeywordsOnly</span> = <span class="ruby-constant">Struct</span>.<span class="ruby-identifier">new</span>(<span class="ruby-value">:foo</span>, <span class="ruby-value">:bar</span>, <span class="ruby-value">keyword_init:</span> <span class="ruby-keyword">true</span>)
<span class="ruby-constant">KeywordsOnly</span>.<span class="ruby-identifier">new</span>(<span class="ruby-value">bar:</span> <span class="ruby-value">1</span>, <span class="ruby-value">foo:</span> <span class="ruby-value">0</span>)
<span class="ruby-comment"># =&gt; #&lt;struct KeywordsOnly foo=0, bar=1&gt;</span>
<span class="ruby-constant">KeywordsOnly</span>.<span class="ruby-identifier">new</span>(<span class="ruby-value">0</span>, <span class="ruby-value">1</span>)
<span class="ruby-comment"># Raises ArgumentError: wrong number of arguments</span>

<span class="ruby-constant">PositionalOnly</span> = <span class="ruby-constant">Struct</span>.<span class="ruby-identifier">new</span>(<span class="ruby-value">:foo</span>, <span class="ruby-value">:bar</span>, <span class="ruby-value">keyword_init:</span> <span class="ruby-keyword">false</span>)
<span class="ruby-constant">PositionalOnly</span>.<span class="ruby-identifier">new</span>(<span class="ruby-value">0</span>, <span class="ruby-value">1</span>)
<span class="ruby-comment"># =&gt; #&lt;struct PositionalOnly foo=0, bar=1&gt;</span>
<span class="ruby-constant">PositionalOnly</span>.<span class="ruby-identifier">new</span>(<span class="ruby-value">bar:</span> <span class="ruby-value">1</span>, <span class="ruby-value">foo:</span> <span class="ruby-value">0</span>)
<span class="ruby-comment"># =&gt; #&lt;struct PositionalOnly foo={:foo=&gt;1, :bar=&gt;2}, bar=nil&gt;</span>
<span class="ruby-comment"># Note that no error is raised, but arguments treated as one hash value</span>

<span class="ruby-comment"># Same as not providing keyword_init:</span>
<span class="ruby-constant">Any</span> = <span class="ruby-constant">Struct</span>.<span class="ruby-identifier">new</span>(<span class="ruby-value">:foo</span>, <span class="ruby-value">:bar</span>, <span class="ruby-value">keyword_init:</span> <span class="ruby-keyword">nil</span>)
<span class="ruby-constant">Any</span>.<span class="ruby-identifier">new</span>(<span class="ruby-value">foo:</span> <span class="ruby-value">1</span>, <span class="ruby-value">bar:</span> <span class="ruby-value">2</span>)
<span class="ruby-comment"># =&gt; #&lt;struct Any foo=1, bar=2&gt;</span>
<span class="ruby-constant">Any</span>.<span class="ruby-identifier">new</span>(<span class="ruby-value">1</span>, <span class="ruby-value">2</span>)
<span class="ruby-comment"># =&gt; #&lt;struct Any foo=1, bar=2&gt;</span>
</pre>

                              <div class="method-source-code" id="new-source">
            <pre>static VALUE
rb_struct_s_def(int argc, VALUE *argv, VALUE klass)
{
    VALUE name = Qnil, rest, keyword_init = Qnil;
    long i;
    VALUE st;
    VALUE opt;

    argc = rb_scan_args(argc, argv, &quot;0*:&quot;, NULL, &amp;opt);
    if (argc &gt;= 1 &amp;&amp; !SYMBOL_P(argv[0])) {
        name = argv[0];
        --argc;
        ++argv;
    }

    if (!NIL_P(opt)) {
        static ID keyword_ids[1];

        if (!keyword_ids[0]) {
            keyword_ids[0] = rb_intern(&quot;keyword_init&quot;);
        }
        rb_get_kwargs(opt, keyword_ids, 0, 1, &amp;keyword_init);
        if (UNDEF_P(keyword_init)) {
            keyword_init = Qnil;
        }
        else if (RTEST(keyword_init)) {
            keyword_init = Qtrue;
        }
    }

    rest = rb_ident_hash_new();
    RBASIC_CLEAR_CLASS(rest);
    for (i=0; i&lt;argc; i++) {
        VALUE mem = rb_to_symbol(argv[i]);
        if (rb_is_attrset_sym(mem)) {
            rb_raise(rb_eArgError, &quot;invalid struct member: %&quot;PRIsVALUE, mem);
        }
        if (RTEST(rb_hash_has_key(rest, mem))) {
            rb_raise(rb_eArgError, &quot;duplicate member: %&quot;PRIsVALUE, mem);
        }
        rb_hash_aset(rest, mem, Qtrue);
    }
    rest = rb_hash_keys(rest);
    RBASIC_CLEAR_CLASS(rest);
    OBJ_FREEZE_RAW(rest);
    if (NIL_P(name)) {
        st = anonymous_struct(klass);
    }
    else {
        st = new_struct(name, klass);
    }
    setup_struct(st, rest);
    rb_ivar_set(st, id_keyword_init, keyword_init);
    if (rb_block_given_p()) {
        rb_mod_module_eval(0, 0, st);
    }

    return st;
}</pre>
                              </div>
                            </div>


                          </div>

                          </section>

                <section id="public-instance-5Buntitled-5D-method-details" class="method-section">
                <header>
                <h3>Public Instance Methods</h3>
                </header>

                  <div id="method-i-3D-3D" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          self == other &rarr; true or false
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns  <code>true</code> if and only if the following are true; otherwise returns <code>false</code>:</p>
<ul><li>
<p><code>other.class == self.class</code>.</p>
</li><li>
<p>For each member name <code>name</code>, <code>other.name == self.name</code>.</p>
</li></ul>

<p>Examples:</p>

<pre class="ruby"><span class="ruby-constant">Customer</span> = <span class="ruby-constant">Struct</span>.<span class="ruby-identifier">new</span>(<span class="ruby-value">:name</span>, <span class="ruby-value">:address</span>, <span class="ruby-value">:zip</span>)
<span class="ruby-identifier">joe</span>    = <span class="ruby-constant">Customer</span>.<span class="ruby-identifier">new</span>(<span class="ruby-string">&quot;Joe Smith&quot;</span>, <span class="ruby-string">&quot;123 Maple, Anytown NC&quot;</span>, <span class="ruby-value">12345</span>)
<span class="ruby-identifier">joe_jr</span> = <span class="ruby-constant">Customer</span>.<span class="ruby-identifier">new</span>(<span class="ruby-string">&quot;Joe Smith&quot;</span>, <span class="ruby-string">&quot;123 Maple, Anytown NC&quot;</span>, <span class="ruby-value">12345</span>)
<span class="ruby-identifier">joe_jr</span> <span class="ruby-operator">==</span> <span class="ruby-identifier">joe</span> <span class="ruby-comment"># =&gt; true</span>
<span class="ruby-identifier">joe_jr</span>[<span class="ruby-value">:name</span>] = <span class="ruby-string">&#39;Joe Smith, Jr.&#39;</span>
<span class="ruby-comment"># =&gt; &quot;Joe Smith, Jr.&quot;</span>
<span class="ruby-identifier">joe_jr</span> <span class="ruby-operator">==</span> <span class="ruby-identifier">joe</span> <span class="ruby-comment"># =&gt; false</span>
</pre>

                              <div class="method-source-code" id="3D-3D-source">
            <pre>static VALUE
rb_struct_equal(VALUE s, VALUE s2)
{
    if (s == s2) return Qtrue;
    if (!RB_TYPE_P(s2, T_STRUCT)) return Qfalse;
    if (rb_obj_class(s) != rb_obj_class(s2)) return Qfalse;
    if (RSTRUCT_LEN(s) != RSTRUCT_LEN(s2)) {
        rb_bug(&quot;inconsistent struct&quot;); /* should never happen */
    }

    return rb_exec_recursive_paired(recursive_equal, s, s2, s2);
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-5B-5D" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          struct[name] &rarr; object
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>
                      <div class="method-heading">
                        <span class="method-callseq">
                          struct[n] &rarr; object
                              </span>
                            </div>

                            <div class="method-description">
                              <p>Returns a value from <code>self</code>.</p>

<p>With symbol or string argument <code>name</code> given, returns the value for the named member:</p>

<pre class="ruby"><span class="ruby-constant">Customer</span> = <span class="ruby-constant">Struct</span>.<span class="ruby-identifier">new</span>(<span class="ruby-value">:name</span>, <span class="ruby-value">:address</span>, <span class="ruby-value">:zip</span>)
<span class="ruby-identifier">joe</span> = <span class="ruby-constant">Customer</span>.<span class="ruby-identifier">new</span>(<span class="ruby-string">&quot;Joe Smith&quot;</span>, <span class="ruby-string">&quot;123 Maple, Anytown NC&quot;</span>, <span class="ruby-value">12345</span>)
<span class="ruby-identifier">joe</span>[<span class="ruby-value">:zip</span>] <span class="ruby-comment"># =&gt; 12345</span>
</pre>

<p>Raises <a href="NameError.html"><code>NameError</code></a> if <code>name</code> is not the name of a member.</p>

<p>With integer argument <code>n</code> given, returns <code>self.values[n]</code> if <code>n</code> is in range; see <a href="Array.html#class-Array-label-Array+Indexes">Array Indexes at <code>Array</code></a>:</p>

<pre class="ruby"><span class="ruby-identifier">joe</span>[<span class="ruby-value">2</span>]  <span class="ruby-comment"># =&gt; 12345</span>
<span class="ruby-identifier">joe</span>[<span class="ruby-value">-2</span>] <span class="ruby-comment"># =&gt; &quot;123 Maple, Anytown NC&quot;</span>
</pre>

<p>Raises <a href="IndexError.html"><code>IndexError</code></a> if <code>n</code> is out of range.</p>

                              <div class="method-source-code" id="5B-5D-source">
            <pre>VALUE
rb_struct_aref(VALUE s, VALUE idx)
{
    int i = rb_struct_pos(s, &amp;idx);
    if (i &lt; 0) invalid_struct_pos(s, idx);
    return RSTRUCT_GET(s, i);
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-5B-5D-3D" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          struct[name] = value &rarr; value
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>
                      <div class="method-heading">
                        <span class="method-callseq">
                          struct[n] = value &rarr; value
                              </span>
                            </div>

                            <div class="method-description">
                              <p>Assigns a value to a member.</p>

<p>With symbol or string argument <code>name</code> given, assigns the given <code>value</code> to the named member; returns <code>value</code>:</p>

<pre class="ruby"><span class="ruby-constant">Customer</span> = <span class="ruby-constant">Struct</span>.<span class="ruby-identifier">new</span>(<span class="ruby-value">:name</span>, <span class="ruby-value">:address</span>, <span class="ruby-value">:zip</span>)
<span class="ruby-identifier">joe</span> = <span class="ruby-constant">Customer</span>.<span class="ruby-identifier">new</span>(<span class="ruby-string">&quot;Joe Smith&quot;</span>, <span class="ruby-string">&quot;123 Maple, Anytown NC&quot;</span>, <span class="ruby-value">12345</span>)
<span class="ruby-identifier">joe</span>[<span class="ruby-value">:zip</span>] = <span class="ruby-value">54321</span> <span class="ruby-comment"># =&gt; 54321</span>
<span class="ruby-identifier">joe</span> <span class="ruby-comment"># =&gt; #&lt;struct Customer name=&quot;Joe Smith&quot;, address=&quot;123 Maple, Anytown NC&quot;, zip=54321&gt;</span>
</pre>

<p>Raises <a href="NameError.html"><code>NameError</code></a> if <code>name</code> is not the name of a member.</p>

<p>With integer argument <code>n</code> given, assigns the given <code>value</code> to the <code>n</code>-th member if <code>n</code> is in range; see <a href="Array.html#class-Array-label-Array+Indexes">Array Indexes at <code>Array</code></a>:</p>

<pre class="ruby"><span class="ruby-identifier">joe</span> = <span class="ruby-constant">Customer</span>.<span class="ruby-identifier">new</span>(<span class="ruby-string">&quot;Joe Smith&quot;</span>, <span class="ruby-string">&quot;123 Maple, Anytown NC&quot;</span>, <span class="ruby-value">12345</span>)
<span class="ruby-identifier">joe</span>[<span class="ruby-value">2</span>] = <span class="ruby-value">54321</span>           <span class="ruby-comment"># =&gt; 54321</span>
<span class="ruby-identifier">joe</span>[<span class="ruby-value">-3</span>] = <span class="ruby-string">&#39;Joseph Smith&#39;</span> <span class="ruby-comment"># =&gt; &quot;Joseph Smith&quot;</span>
<span class="ruby-identifier">joe</span> <span class="ruby-comment"># =&gt; #&lt;struct Customer name=&quot;Joseph Smith&quot;, address=&quot;123 Maple, Anytown NC&quot;, zip=54321&gt;</span>
</pre>

<p>Raises <a href="IndexError.html"><code>IndexError</code></a> if <code>n</code> is out of range.</p>

                              <div class="method-source-code" id="5B-5D-3D-source">
            <pre>VALUE
rb_struct_aset(VALUE s, VALUE idx, VALUE val)
{
    int i = rb_struct_pos(s, &amp;idx);
    if (i &lt; 0) invalid_struct_pos(s, idx);
    rb_struct_modify(s);
    RSTRUCT_SET(s, i, val);
    return val;
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-deconstruct" class="method-detail method-alias">
                            <div class="method-heading">
                              <span class="method-name">deconstruct</span><span
                                class="method-args">()</span>
                            </div>

                            <div class="method-description">
                              <p>Returns the values in <code>self</code> as an array:</p>

<pre class="ruby"><span class="ruby-constant">Customer</span> = <span class="ruby-constant">Struct</span>.<span class="ruby-identifier">new</span>(<span class="ruby-value">:name</span>, <span class="ruby-value">:address</span>, <span class="ruby-value">:zip</span>)
<span class="ruby-identifier">joe</span> = <span class="ruby-constant">Customer</span>.<span class="ruby-identifier">new</span>(<span class="ruby-string">&quot;Joe Smith&quot;</span>, <span class="ruby-string">&quot;123 Maple, Anytown NC&quot;</span>, <span class="ruby-value">12345</span>)
<span class="ruby-identifier">joe</span>.<span class="ruby-identifier">to_a</span> <span class="ruby-comment"># =&gt; [&quot;Joe Smith&quot;, &quot;123 Maple, Anytown NC&quot;, 12345]</span>
</pre>

<p>Related: <a href="Struct.html#method-i-members"><code>members</code></a>.</p>

                            </div>


                            <div class="aliases">
                              Alias for: <a href="Struct.html#method-i-to_a">to_a</a>
                            </div>
                          </div>

                  <div id="method-i-deconstruct_keys" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          deconstruct_keys(array_of_names) &rarr; hash
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns a hash of the name/value pairs for the given member names.</p>

<pre class="ruby"><span class="ruby-constant">Customer</span> = <span class="ruby-constant">Struct</span>.<span class="ruby-identifier">new</span>(<span class="ruby-value">:name</span>, <span class="ruby-value">:address</span>, <span class="ruby-value">:zip</span>)
<span class="ruby-identifier">joe</span> = <span class="ruby-constant">Customer</span>.<span class="ruby-identifier">new</span>(<span class="ruby-string">&quot;Joe Smith&quot;</span>, <span class="ruby-string">&quot;123 Maple, Anytown NC&quot;</span>, <span class="ruby-value">12345</span>)
<span class="ruby-identifier">h</span> = <span class="ruby-identifier">joe</span>.<span class="ruby-identifier">deconstruct_keys</span>([<span class="ruby-value">:zip</span>, <span class="ruby-value">:address</span>])
<span class="ruby-identifier">h</span> <span class="ruby-comment"># =&gt; {:zip=&gt;12345, :address=&gt;&quot;123 Maple, Anytown NC&quot;}</span>
</pre>

<p>Returns all names and values if <code>array_of_names</code> is <code>nil</code>:</p>

<pre class="ruby"><span class="ruby-identifier">h</span> = <span class="ruby-identifier">joe</span>.<span class="ruby-identifier">deconstruct_keys</span>(<span class="ruby-keyword">nil</span>)
<span class="ruby-identifier">h</span> <span class="ruby-comment"># =&gt; {:name=&gt;&quot;Joseph Smith, Jr.&quot;, :address=&gt;&quot;123 Maple, Anytown NC&quot;, :zip=&gt;12345}</span>
</pre>

                              <div class="method-source-code" id="deconstruct_keys-source">
            <pre>static VALUE
rb_struct_deconstruct_keys(VALUE s, VALUE keys)
{
    VALUE h;
    long i;

    if (NIL_P(keys)) {
        return rb_struct_to_h(s);
    }
    if (UNLIKELY(!RB_TYPE_P(keys, T_ARRAY))) {
        rb_raise(rb_eTypeError,
                 &quot;wrong argument type %&quot;PRIsVALUE&quot; (expected Array or nil)&quot;,
                 rb_obj_class(keys));

    }
    if (RSTRUCT_LEN(s) &lt; RARRAY_LEN(keys)) {
        return rb_hash_new_with_size(0);
    }
    h = rb_hash_new_with_size(RARRAY_LEN(keys));
    for (i=0; i&lt;RARRAY_LEN(keys); i++) {
        VALUE key = RARRAY_AREF(keys, i);
        int i = rb_struct_pos(s, &amp;key);
        if (i &lt; 0) {
            return h;
        }
        rb_hash_aset(h, key, RSTRUCT_GET(s, i));
    }
    return h;
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-dig" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          dig(name, *identifiers) &rarr; object
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>
                      <div class="method-heading">
                        <span class="method-callseq">
                          dig(n, *identifiers) &rarr; object
                              </span>
                            </div>

                            <div class="method-description">
                              <p>Finds and returns an object among nested objects. The nested objects may be instances of various classes. See <a href="dig_methods_rdoc.html">Dig Methods</a>.</p>

<p>Given symbol or string argument <code>name</code>, returns the object that is specified by <code>name</code> and <code>identifiers</code>:</p>

<pre class="ruby"><span class="ruby-constant">Foo</span> = <span class="ruby-constant">Struct</span>.<span class="ruby-identifier">new</span>(<span class="ruby-value">:a</span>)
<span class="ruby-identifier">f</span> = <span class="ruby-constant">Foo</span>.<span class="ruby-identifier">new</span>(<span class="ruby-constant">Foo</span>.<span class="ruby-identifier">new</span>({<span class="ruby-value">b:</span> [<span class="ruby-value">1</span>, <span class="ruby-value">2</span>, <span class="ruby-value">3</span>]}))
<span class="ruby-identifier">f</span>.<span class="ruby-identifier">dig</span>(<span class="ruby-value">:a</span>) <span class="ruby-comment"># =&gt; #&lt;struct Foo a={:b=&gt;[1, 2, 3]}&gt;</span>
<span class="ruby-identifier">f</span>.<span class="ruby-identifier">dig</span>(<span class="ruby-value">:a</span>, <span class="ruby-value">:a</span>) <span class="ruby-comment"># =&gt; {:b=&gt;[1, 2, 3]}</span>
<span class="ruby-identifier">f</span>.<span class="ruby-identifier">dig</span>(<span class="ruby-value">:a</span>, <span class="ruby-value">:a</span>, <span class="ruby-value">:b</span>) <span class="ruby-comment"># =&gt; [1, 2, 3]</span>
<span class="ruby-identifier">f</span>.<span class="ruby-identifier">dig</span>(<span class="ruby-value">:a</span>, <span class="ruby-value">:a</span>, <span class="ruby-value">:b</span>, <span class="ruby-value">0</span>) <span class="ruby-comment"># =&gt; 1</span>
<span class="ruby-identifier">f</span>.<span class="ruby-identifier">dig</span>(<span class="ruby-value">:b</span>, <span class="ruby-value">0</span>) <span class="ruby-comment"># =&gt; nil</span>
</pre>

<p>Given integer argument <code>n</code>, returns the object that is specified by <code>n</code> and <code>identifiers</code>:</p>

<pre class="ruby"><span class="ruby-identifier">f</span>.<span class="ruby-identifier">dig</span>(<span class="ruby-value">0</span>) <span class="ruby-comment"># =&gt; #&lt;struct Foo a={:b=&gt;[1, 2, 3]}&gt;</span>
<span class="ruby-identifier">f</span>.<span class="ruby-identifier">dig</span>(<span class="ruby-value">0</span>, <span class="ruby-value">0</span>) <span class="ruby-comment"># =&gt; {:b=&gt;[1, 2, 3]}</span>
<span class="ruby-identifier">f</span>.<span class="ruby-identifier">dig</span>(<span class="ruby-value">0</span>, <span class="ruby-value">0</span>, <span class="ruby-value">:b</span>) <span class="ruby-comment"># =&gt; [1, 2, 3]</span>
<span class="ruby-identifier">f</span>.<span class="ruby-identifier">dig</span>(<span class="ruby-value">0</span>, <span class="ruby-value">0</span>, <span class="ruby-value">:b</span>, <span class="ruby-value">0</span>) <span class="ruby-comment"># =&gt; 1</span>
<span class="ruby-identifier">f</span>.<span class="ruby-identifier">dig</span>(<span class="ruby-value">:b</span>, <span class="ruby-value">0</span>) <span class="ruby-comment"># =&gt; nil</span>
</pre>

                              <div class="method-source-code" id="dig-source">
            <pre>static VALUE
rb_struct_dig(int argc, VALUE *argv, VALUE self)
{
    rb_check_arity(argc, 1, UNLIMITED_ARGUMENTS);
    self = rb_struct_lookup(self, *argv);
    if (!--argc) return self;
    ++argv;
    return rb_obj_dig(argc, argv, self, Qnil);
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-each" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          each {|value| ... } &rarr; self
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>
                      <div class="method-heading">
                        <span class="method-callseq">
                          each &rarr; enumerator
                              </span>
                            </div>

                            <div class="method-description">
                              <p>Calls the given block with the value of each member; returns <code>self</code>:</p>

<pre class="ruby"><span class="ruby-constant">Customer</span> = <span class="ruby-constant">Struct</span>.<span class="ruby-identifier">new</span>(<span class="ruby-value">:name</span>, <span class="ruby-value">:address</span>, <span class="ruby-value">:zip</span>)
<span class="ruby-identifier">joe</span> = <span class="ruby-constant">Customer</span>.<span class="ruby-identifier">new</span>(<span class="ruby-string">&quot;Joe Smith&quot;</span>, <span class="ruby-string">&quot;123 Maple, Anytown NC&quot;</span>, <span class="ruby-value">12345</span>)
<span class="ruby-identifier">joe</span>.<span class="ruby-identifier">each</span> {<span class="ruby-operator">|</span><span class="ruby-identifier">value</span><span class="ruby-operator">|</span> <span class="ruby-identifier">p</span> <span class="ruby-identifier">value</span> }
</pre>

<p>Output:</p>

<pre class="ruby"><span class="ruby-string">&quot;Joe Smith&quot;</span>
<span class="ruby-string">&quot;123 Maple, Anytown NC&quot;</span>
<span class="ruby-value">12345</span>
</pre>

<p>Returns an <a href="Enumerator.html"><code>Enumerator</code></a> if no block is given.</p>

<p>Related: <a href="Struct.html#method-i-each_pair"><code>each_pair</code></a>.</p>

                              <div class="method-source-code" id="each-source">
            <pre>static VALUE
rb_struct_each(VALUE s)
{
    long i;

    RETURN_SIZED_ENUMERATOR(s, 0, 0, struct_enum_size);
    for (i=0; i&lt;RSTRUCT_LEN(s); i++) {
        rb_yield(RSTRUCT_GET(s, i));
    }
    return s;
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-each_pair" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          each_pair {|(name, value)| ... } &rarr; self
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>
                      <div class="method-heading">
                        <span class="method-callseq">
                          each_pair &rarr; enumerator
                              </span>
                            </div>

                            <div class="method-description">
                              <p>Calls the given block with each member name/value pair; returns <code>self</code>:</p>

<pre class="ruby"><span class="ruby-constant">Customer</span> = <span class="ruby-constant">Struct</span>.<span class="ruby-identifier">new</span>(<span class="ruby-value">:name</span>, <span class="ruby-value">:address</span>, <span class="ruby-value">:zip</span>) <span class="ruby-comment"># =&gt; Customer</span>
<span class="ruby-identifier">joe</span> = <span class="ruby-constant">Customer</span>.<span class="ruby-identifier">new</span>(<span class="ruby-string">&quot;Joe Smith&quot;</span>, <span class="ruby-string">&quot;123 Maple, Anytown NC&quot;</span>, <span class="ruby-value">12345</span>)
<span class="ruby-identifier">joe</span>.<span class="ruby-identifier">each_pair</span> {<span class="ruby-operator">|</span>(<span class="ruby-identifier">name</span>, <span class="ruby-identifier">value</span>)<span class="ruby-operator">|</span> <span class="ruby-identifier">p</span> <span class="ruby-node">&quot;#{name} =&gt; #{value}&quot;</span> }
</pre>

<p>Output:</p>

<pre class="ruby"><span class="ruby-string">&quot;name =&gt; Joe Smith&quot;</span>
<span class="ruby-string">&quot;address =&gt; 123 Maple, Anytown NC&quot;</span>
<span class="ruby-string">&quot;zip =&gt; 12345&quot;</span>
</pre>

<p>Returns an <a href="Enumerator.html"><code>Enumerator</code></a> if no block is given.</p>

<p>Related: <a href="Struct.html#method-i-each"><code>each</code></a>.</p>

                              <div class="method-source-code" id="each_pair-source">
            <pre>static VALUE
rb_struct_each_pair(VALUE s)
{
    VALUE members;
    long i;

    RETURN_SIZED_ENUMERATOR(s, 0, 0, struct_enum_size);
    members = rb_struct_members(s);
    if (rb_block_pair_yield_optimizable()) {
        for (i=0; i&lt;RSTRUCT_LEN(s); i++) {
            VALUE key = rb_ary_entry(members, i);
            VALUE value = RSTRUCT_GET(s, i);
            rb_yield_values(2, key, value);
        }
    }
    else {
        for (i=0; i&lt;RSTRUCT_LEN(s); i++) {
            VALUE key = rb_ary_entry(members, i);
            VALUE value = RSTRUCT_GET(s, i);
            rb_yield(rb_assoc_new(key, value));
        }
    }
    return s;
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-eql-3F" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          eql?(other) &rarr; true or false
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns <code>true</code> if and only if the following are true; otherwise returns <code>false</code>:</p>
<ul><li>
<p><code>other.class == self.class</code>.</p>
</li><li>
<p>For each member name <code>name</code>, <code>other.name.eql?(self.name)</code>.</p>

<pre class="ruby"><span class="ruby-constant">Customer</span> = <span class="ruby-constant">Struct</span>.<span class="ruby-identifier">new</span>(<span class="ruby-value">:name</span>, <span class="ruby-value">:address</span>, <span class="ruby-value">:zip</span>)
<span class="ruby-identifier">joe</span>    = <span class="ruby-constant">Customer</span>.<span class="ruby-identifier">new</span>(<span class="ruby-string">&quot;Joe Smith&quot;</span>, <span class="ruby-string">&quot;123 Maple, Anytown NC&quot;</span>, <span class="ruby-value">12345</span>)
<span class="ruby-identifier">joe_jr</span> = <span class="ruby-constant">Customer</span>.<span class="ruby-identifier">new</span>(<span class="ruby-string">&quot;Joe Smith&quot;</span>, <span class="ruby-string">&quot;123 Maple, Anytown NC&quot;</span>, <span class="ruby-value">12345</span>)
<span class="ruby-identifier">joe_jr</span>.<span class="ruby-identifier">eql?</span>(<span class="ruby-identifier">joe</span>) <span class="ruby-comment"># =&gt; true</span>
<span class="ruby-identifier">joe_jr</span>[<span class="ruby-value">:name</span>] = <span class="ruby-string">&#39;Joe Smith, Jr.&#39;</span>
<span class="ruby-identifier">joe_jr</span>.<span class="ruby-identifier">eql?</span>(<span class="ruby-identifier">joe</span>) <span class="ruby-comment"># =&gt; false</span>
</pre>
</li></ul>

<p>Related: <a href="BasicObject.html#method-i-3D-3D"><code>Object#==</code></a>.</p>

                              <div class="method-source-code" id="eql-3F-source">
            <pre>static VALUE
rb_struct_eql(VALUE s, VALUE s2)
{
    if (s == s2) return Qtrue;
    if (!RB_TYPE_P(s2, T_STRUCT)) return Qfalse;
    if (rb_obj_class(s) != rb_obj_class(s2)) return Qfalse;
    if (RSTRUCT_LEN(s) != RSTRUCT_LEN(s2)) {
        rb_bug(&quot;inconsistent struct&quot;); /* should never happen */
    }

    return rb_exec_recursive_paired(recursive_eql, s, s2, s2);
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-filter" class="method-detail method-alias">
                            <div class="method-heading">
                              <span class="method-name">filter</span><span
                                class="method-args">(*args)</span>
                            </div>

                            <div class="method-description">
                              <p>With a block given, returns an array of values from <code>self</code> for which the block returns a truthy value:</p>

<pre class="ruby"><span class="ruby-constant">Customer</span> = <span class="ruby-constant">Struct</span>.<span class="ruby-identifier">new</span>(<span class="ruby-value">:name</span>, <span class="ruby-value">:address</span>, <span class="ruby-value">:zip</span>)
<span class="ruby-identifier">joe</span> = <span class="ruby-constant">Customer</span>.<span class="ruby-identifier">new</span>(<span class="ruby-string">&quot;Joe Smith&quot;</span>, <span class="ruby-string">&quot;123 Maple, Anytown NC&quot;</span>, <span class="ruby-value">12345</span>)
<span class="ruby-identifier">a</span> = <span class="ruby-identifier">joe</span>.<span class="ruby-identifier">select</span> {<span class="ruby-operator">|</span><span class="ruby-identifier">value</span><span class="ruby-operator">|</span> <span class="ruby-identifier">value</span>.<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">String</span>) }
<span class="ruby-identifier">a</span> <span class="ruby-comment"># =&gt; [&quot;Joe Smith&quot;, &quot;123 Maple, Anytown NC&quot;]</span>
<span class="ruby-identifier">a</span> = <span class="ruby-identifier">joe</span>.<span class="ruby-identifier">select</span> {<span class="ruby-operator">|</span><span class="ruby-identifier">value</span><span class="ruby-operator">|</span> <span class="ruby-identifier">value</span>.<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">Integer</span>) }
<span class="ruby-identifier">a</span> <span class="ruby-comment"># =&gt; [12345]</span>
</pre>

<p>With no block given, returns an <a href="Enumerator.html"><code>Enumerator</code></a>.</p>

                            </div>


                            <div class="aliases">
                              Alias for: <a href="Struct.html#method-i-select">select</a>
                            </div>
                          </div>

                  <div id="method-i-hash" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          hash &rarr; integer
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns the integer hash value for <code>self</code>.</p>

<p>Two structs of the same class and with the same content will have the same hash code (and will compare using <a href="Struct.html#method-i-eql-3F"><code>Struct#eql?</code></a>):</p>

<pre class="ruby"><span class="ruby-constant">Customer</span> = <span class="ruby-constant">Struct</span>.<span class="ruby-identifier">new</span>(<span class="ruby-value">:name</span>, <span class="ruby-value">:address</span>, <span class="ruby-value">:zip</span>)
<span class="ruby-identifier">joe</span>    = <span class="ruby-constant">Customer</span>.<span class="ruby-identifier">new</span>(<span class="ruby-string">&quot;Joe Smith&quot;</span>, <span class="ruby-string">&quot;123 Maple, Anytown NC&quot;</span>, <span class="ruby-value">12345</span>)
<span class="ruby-identifier">joe_jr</span> = <span class="ruby-constant">Customer</span>.<span class="ruby-identifier">new</span>(<span class="ruby-string">&quot;Joe Smith&quot;</span>, <span class="ruby-string">&quot;123 Maple, Anytown NC&quot;</span>, <span class="ruby-value">12345</span>)
<span class="ruby-identifier">joe</span>.<span class="ruby-identifier">hash</span> <span class="ruby-operator">==</span> <span class="ruby-identifier">joe_jr</span>.<span class="ruby-identifier">hash</span> <span class="ruby-comment"># =&gt; true</span>
<span class="ruby-identifier">joe_jr</span>[<span class="ruby-value">:name</span>] = <span class="ruby-string">&#39;Joe Smith, Jr.&#39;</span>
<span class="ruby-identifier">joe</span>.<span class="ruby-identifier">hash</span> <span class="ruby-operator">==</span> <span class="ruby-identifier">joe_jr</span>.<span class="ruby-identifier">hash</span> <span class="ruby-comment"># =&gt; false</span>
</pre>

<p>Related: <a href="Object.html#method-i-hash"><code>Object#hash</code></a>.</p>

                              <div class="method-source-code" id="hash-source">
            <pre>static VALUE
rb_struct_hash(VALUE s)
{
    long i, len;
    st_index_t h;
    VALUE n;

    h = rb_hash_start(rb_hash(rb_obj_class(s)));
    len = RSTRUCT_LEN(s);
    for (i = 0; i &lt; len; i++) {
        n = rb_hash(RSTRUCT_GET(s, i));
        h = rb_hash_uint(h, NUM2LONG(n));
    }
    h = rb_hash_end(h);
    return ST2FIX(h);
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-inspect" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          inspect &rarr; string
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns a string representation of <code>self</code>:</p>

<pre class="ruby"><span class="ruby-constant">Customer</span> = <span class="ruby-constant">Struct</span>.<span class="ruby-identifier">new</span>(<span class="ruby-value">:name</span>, <span class="ruby-value">:address</span>, <span class="ruby-value">:zip</span>) <span class="ruby-comment"># =&gt; Customer</span>
<span class="ruby-identifier">joe</span> = <span class="ruby-constant">Customer</span>.<span class="ruby-identifier">new</span>(<span class="ruby-string">&quot;Joe Smith&quot;</span>, <span class="ruby-string">&quot;123 Maple, Anytown NC&quot;</span>, <span class="ruby-value">12345</span>)
<span class="ruby-identifier">joe</span>.<span class="ruby-identifier">inspect</span> <span class="ruby-comment"># =&gt; &quot;#&lt;struct Customer name=\&quot;Joe Smith\&quot;, address=\&quot;123 Maple, Anytown NC\&quot;, zip=12345&gt;&quot;</span>
</pre>

                              <div class="method-source-code" id="inspect-source">
            <pre>static VALUE
rb_struct_inspect(VALUE s)
{
    return rb_exec_recursive(inspect_struct, s, rb_str_new2(&quot;#&lt;struct &quot;));
}</pre>
                              </div>
                            </div>

                            <div class="aliases">
                              Also aliased as: <a href="Struct.html#method-i-to_s">to_s</a>
                            </div>

                          </div>

                  <div id="method-i-length" class="method-detail method-alias">
                            <div class="method-heading">
                              <span class="method-name">length</span><span
                                class="method-args">()</span>
                            </div>

                            <div class="method-description">
                              <p>Returns the number of members.</p>

<pre class="ruby"><span class="ruby-constant">Customer</span> = <span class="ruby-constant">Struct</span>.<span class="ruby-identifier">new</span>(<span class="ruby-value">:name</span>, <span class="ruby-value">:address</span>, <span class="ruby-value">:zip</span>)
<span class="ruby-identifier">joe</span> = <span class="ruby-constant">Customer</span>.<span class="ruby-identifier">new</span>(<span class="ruby-string">&quot;Joe Smith&quot;</span>, <span class="ruby-string">&quot;123 Maple, Anytown NC&quot;</span>, <span class="ruby-value">12345</span>)
<span class="ruby-identifier">joe</span>.<span class="ruby-identifier">size</span> <span class="ruby-comment">#=&gt; 3</span>
</pre>

                            </div>


                            <div class="aliases">
                              Alias for: <a href="Struct.html#method-i-size">size</a>
                            </div>
                          </div>

                  <div id="method-i-members" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          members &rarr; array_of_symbols
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns the member names from <code>self</code> as an array:</p>

<pre class="ruby"><span class="ruby-constant">Customer</span> = <span class="ruby-constant">Struct</span>.<span class="ruby-identifier">new</span>(<span class="ruby-value">:name</span>, <span class="ruby-value">:address</span>, <span class="ruby-value">:zip</span>)
<span class="ruby-constant">Customer</span>.<span class="ruby-identifier">new</span>.<span class="ruby-identifier">members</span> <span class="ruby-comment"># =&gt; [:name, :address, :zip]</span>
</pre>

<p>Related: <a href="Struct.html#method-i-to_a"><code>to_a</code></a>.</p>

                              <div class="method-source-code" id="members-source">
            <pre>static VALUE
rb_struct_members_m(VALUE obj)
{
    return rb_struct_s_members_m(rb_obj_class(obj));
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-select" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          select {|value| ... } &rarr; array
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>
                      <div class="method-heading">
                        <span class="method-callseq">
                          select &rarr; enumerator
                              </span>
                            </div>

                            <div class="method-description">
                              <p>With a block given, returns an array of values from <code>self</code> for which the block returns a truthy value:</p>

<pre class="ruby"><span class="ruby-constant">Customer</span> = <span class="ruby-constant">Struct</span>.<span class="ruby-identifier">new</span>(<span class="ruby-value">:name</span>, <span class="ruby-value">:address</span>, <span class="ruby-value">:zip</span>)
<span class="ruby-identifier">joe</span> = <span class="ruby-constant">Customer</span>.<span class="ruby-identifier">new</span>(<span class="ruby-string">&quot;Joe Smith&quot;</span>, <span class="ruby-string">&quot;123 Maple, Anytown NC&quot;</span>, <span class="ruby-value">12345</span>)
<span class="ruby-identifier">a</span> = <span class="ruby-identifier">joe</span>.<span class="ruby-identifier">select</span> {<span class="ruby-operator">|</span><span class="ruby-identifier">value</span><span class="ruby-operator">|</span> <span class="ruby-identifier">value</span>.<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">String</span>) }
<span class="ruby-identifier">a</span> <span class="ruby-comment"># =&gt; [&quot;Joe Smith&quot;, &quot;123 Maple, Anytown NC&quot;]</span>
<span class="ruby-identifier">a</span> = <span class="ruby-identifier">joe</span>.<span class="ruby-identifier">select</span> {<span class="ruby-operator">|</span><span class="ruby-identifier">value</span><span class="ruby-operator">|</span> <span class="ruby-identifier">value</span>.<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">Integer</span>) }
<span class="ruby-identifier">a</span> <span class="ruby-comment"># =&gt; [12345]</span>
</pre>

<p>With no block given, returns an <a href="Enumerator.html"><code>Enumerator</code></a>.</p>

                              <div class="method-source-code" id="select-source">
            <pre>static VALUE
rb_struct_select(int argc, VALUE *argv, VALUE s)
{
    VALUE result;
    long i;

    rb_check_arity(argc, 0, 0);
    RETURN_SIZED_ENUMERATOR(s, 0, 0, struct_enum_size);
    result = rb_ary_new();
    for (i = 0; i &lt; RSTRUCT_LEN(s); i++) {
        if (RTEST(rb_yield(RSTRUCT_GET(s, i)))) {
            rb_ary_push(result, RSTRUCT_GET(s, i));
        }
    }

    return result;
}</pre>
                              </div>
                            </div>

                            <div class="aliases">
                              Also aliased as: <a href="Struct.html#method-i-filter">filter</a>
                            </div>

                          </div>

                  <div id="method-i-size" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          size &rarr; integer
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns the number of members.</p>

<pre class="ruby"><span class="ruby-constant">Customer</span> = <span class="ruby-constant">Struct</span>.<span class="ruby-identifier">new</span>(<span class="ruby-value">:name</span>, <span class="ruby-value">:address</span>, <span class="ruby-value">:zip</span>)
<span class="ruby-identifier">joe</span> = <span class="ruby-constant">Customer</span>.<span class="ruby-identifier">new</span>(<span class="ruby-string">&quot;Joe Smith&quot;</span>, <span class="ruby-string">&quot;123 Maple, Anytown NC&quot;</span>, <span class="ruby-value">12345</span>)
<span class="ruby-identifier">joe</span>.<span class="ruby-identifier">size</span> <span class="ruby-comment">#=&gt; 3</span>
</pre>

                              <div class="method-source-code" id="size-source">
            <pre>VALUE
rb_struct_size(VALUE s)
{
    return LONG2FIX(RSTRUCT_LEN(s));
}</pre>
                              </div>
                            </div>

                            <div class="aliases">
                              Also aliased as: <a href="Struct.html#method-i-length">length</a>
                            </div>

                          </div>

                  <div id="method-i-to_a" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          to_a     &rarr; array
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns the values in <code>self</code> as an array:</p>

<pre class="ruby"><span class="ruby-constant">Customer</span> = <span class="ruby-constant">Struct</span>.<span class="ruby-identifier">new</span>(<span class="ruby-value">:name</span>, <span class="ruby-value">:address</span>, <span class="ruby-value">:zip</span>)
<span class="ruby-identifier">joe</span> = <span class="ruby-constant">Customer</span>.<span class="ruby-identifier">new</span>(<span class="ruby-string">&quot;Joe Smith&quot;</span>, <span class="ruby-string">&quot;123 Maple, Anytown NC&quot;</span>, <span class="ruby-value">12345</span>)
<span class="ruby-identifier">joe</span>.<span class="ruby-identifier">to_a</span> <span class="ruby-comment"># =&gt; [&quot;Joe Smith&quot;, &quot;123 Maple, Anytown NC&quot;, 12345]</span>
</pre>

<p>Related: <a href="Struct.html#method-i-members"><code>members</code></a>.</p>

                              <div class="method-source-code" id="to_a-source">
            <pre>static VALUE
rb_struct_to_a(VALUE s)
{
    return rb_ary_new4(RSTRUCT_LEN(s), RSTRUCT_CONST_PTR(s));
}</pre>
                              </div>
                            </div>

                            <div class="aliases">
                              Also aliased as: <a href="Struct.html#method-i-values">values</a>, <a href="Struct.html#method-i-deconstruct">deconstruct</a>
                            </div>

                          </div>

                  <div id="method-i-to_h" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          to_h &rarr; hash
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>
                      <div class="method-heading">
                        <span class="method-callseq">
                          to_h {|name, value| ... } &rarr; hash
                              </span>
                            </div>

                            <div class="method-description">
                              <p>Returns a hash containing the name and value for each member:</p>

<pre class="ruby"><span class="ruby-constant">Customer</span> = <span class="ruby-constant">Struct</span>.<span class="ruby-identifier">new</span>(<span class="ruby-value">:name</span>, <span class="ruby-value">:address</span>, <span class="ruby-value">:zip</span>)
<span class="ruby-identifier">joe</span> = <span class="ruby-constant">Customer</span>.<span class="ruby-identifier">new</span>(<span class="ruby-string">&quot;Joe Smith&quot;</span>, <span class="ruby-string">&quot;123 Maple, Anytown NC&quot;</span>, <span class="ruby-value">12345</span>)
<span class="ruby-identifier">h</span> = <span class="ruby-identifier">joe</span>.<span class="ruby-identifier">to_h</span>
<span class="ruby-identifier">h</span> <span class="ruby-comment"># =&gt; {:name=&gt;&quot;Joe Smith&quot;, :address=&gt;&quot;123 Maple, Anytown NC&quot;, :zip=&gt;12345}</span>
</pre>

<p>If a block is given, it is called with each name/value pair; the block should return a 2-element array whose elements will become a key/value pair in the returned hash:</p>

<pre class="ruby"><span class="ruby-identifier">h</span> = <span class="ruby-identifier">joe</span>.<span class="ruby-identifier">to_h</span>{<span class="ruby-operator">|</span><span class="ruby-identifier">name</span>, <span class="ruby-identifier">value</span><span class="ruby-operator">|</span> [<span class="ruby-identifier">name</span>.<span class="ruby-identifier">upcase</span>, <span class="ruby-identifier">value</span>.<span class="ruby-identifier">to_s</span>.<span class="ruby-identifier">upcase</span>]}
<span class="ruby-identifier">h</span> <span class="ruby-comment"># =&gt; {:NAME=&gt;&quot;JOE SMITH&quot;, :ADDRESS=&gt;&quot;123 MAPLE, ANYTOWN NC&quot;, :ZIP=&gt;&quot;12345&quot;}</span>
</pre>

<p>Raises <a href="ArgumentError.html"><code>ArgumentError</code></a> if the block returns an inappropriate value.</p>

                              <div class="method-source-code" id="to_h-source">
            <pre>static VALUE
rb_struct_to_h(VALUE s)
{
    VALUE h = rb_hash_new_with_size(RSTRUCT_LEN(s));
    VALUE members = rb_struct_members(s);
    long i;
    int block_given = rb_block_given_p();

    for (i=0; i&lt;RSTRUCT_LEN(s); i++) {
        VALUE k = rb_ary_entry(members, i), v = RSTRUCT_GET(s, i);
        if (block_given)
            rb_hash_set_pair(h, rb_yield_values(2, k, v));
        else
            rb_hash_aset(h, k, v);
    }
    return h;
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-to_s" class="method-detail method-alias">
                            <div class="method-heading">
                              <span class="method-name">to_s</span><span
                                class="method-args">()</span>
                            </div>

                            <div class="method-description">
                              <p>Returns a string representation of <code>self</code>:</p>

<pre class="ruby"><span class="ruby-constant">Customer</span> = <span class="ruby-constant">Struct</span>.<span class="ruby-identifier">new</span>(<span class="ruby-value">:name</span>, <span class="ruby-value">:address</span>, <span class="ruby-value">:zip</span>) <span class="ruby-comment"># =&gt; Customer</span>
<span class="ruby-identifier">joe</span> = <span class="ruby-constant">Customer</span>.<span class="ruby-identifier">new</span>(<span class="ruby-string">&quot;Joe Smith&quot;</span>, <span class="ruby-string">&quot;123 Maple, Anytown NC&quot;</span>, <span class="ruby-value">12345</span>)
<span class="ruby-identifier">joe</span>.<span class="ruby-identifier">inspect</span> <span class="ruby-comment"># =&gt; &quot;#&lt;struct Customer name=\&quot;Joe Smith\&quot;, address=\&quot;123 Maple, Anytown NC\&quot;, zip=12345&gt;&quot;</span>
</pre>

                            </div>


                            <div class="aliases">
                              Alias for: <a href="Struct.html#method-i-inspect">inspect</a>
                            </div>
                          </div>

                  <div id="method-i-values" class="method-detail method-alias">
                            <div class="method-heading">
                              <span class="method-name">values</span><span
                                class="method-args">()</span>
                            </div>

                            <div class="method-description">
                              <p>Returns the values in <code>self</code> as an array:</p>

<pre class="ruby"><span class="ruby-constant">Customer</span> = <span class="ruby-constant">Struct</span>.<span class="ruby-identifier">new</span>(<span class="ruby-value">:name</span>, <span class="ruby-value">:address</span>, <span class="ruby-value">:zip</span>)
<span class="ruby-identifier">joe</span> = <span class="ruby-constant">Customer</span>.<span class="ruby-identifier">new</span>(<span class="ruby-string">&quot;Joe Smith&quot;</span>, <span class="ruby-string">&quot;123 Maple, Anytown NC&quot;</span>, <span class="ruby-value">12345</span>)
<span class="ruby-identifier">joe</span>.<span class="ruby-identifier">to_a</span> <span class="ruby-comment"># =&gt; [&quot;Joe Smith&quot;, &quot;123 Maple, Anytown NC&quot;, 12345]</span>
</pre>

<p>Related: <a href="Struct.html#method-i-members"><code>members</code></a>.</p>

                            </div>


                            <div class="aliases">
                              Alias for: <a href="Struct.html#method-i-to_a">to_a</a>
                            </div>
                          </div>

                  <div id="method-i-values_at" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          values_at(*integers) &rarr; array
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>
                      <div class="method-heading">
                        <span class="method-callseq">
                          values_at(integer_range) &rarr; array
                              </span>
                            </div>

                            <div class="method-description">
                              <p>Returns an array of values from <code>self</code>.</p>

<p>With integer arguments <code>integers</code> given, returns an array containing each value given by one of <code>integers</code>:</p>

<pre class="ruby"><span class="ruby-constant">Customer</span> = <span class="ruby-constant">Struct</span>.<span class="ruby-identifier">new</span>(<span class="ruby-value">:name</span>, <span class="ruby-value">:address</span>, <span class="ruby-value">:zip</span>)
<span class="ruby-identifier">joe</span> = <span class="ruby-constant">Customer</span>.<span class="ruby-identifier">new</span>(<span class="ruby-string">&quot;Joe Smith&quot;</span>, <span class="ruby-string">&quot;123 Maple, Anytown NC&quot;</span>, <span class="ruby-value">12345</span>)
<span class="ruby-identifier">joe</span>.<span class="ruby-identifier">values_at</span>(<span class="ruby-value">0</span>, <span class="ruby-value">2</span>)    <span class="ruby-comment"># =&gt; [&quot;Joe Smith&quot;, 12345]</span>
<span class="ruby-identifier">joe</span>.<span class="ruby-identifier">values_at</span>(<span class="ruby-value">2</span>, <span class="ruby-value">0</span>)    <span class="ruby-comment"># =&gt; [12345, &quot;Joe Smith&quot;]</span>
<span class="ruby-identifier">joe</span>.<span class="ruby-identifier">values_at</span>(<span class="ruby-value">2</span>, <span class="ruby-value">1</span>, <span class="ruby-value">0</span>) <span class="ruby-comment"># =&gt; [12345, &quot;123 Maple, Anytown NC&quot;, &quot;Joe Smith&quot;]</span>
<span class="ruby-identifier">joe</span>.<span class="ruby-identifier">values_at</span>(<span class="ruby-value">0</span>, <span class="ruby-value">-3</span>)   <span class="ruby-comment"># =&gt; [&quot;Joe Smith&quot;, &quot;Joe Smith&quot;]</span>
</pre>

<p>Raises <a href="IndexError.html"><code>IndexError</code></a> if any of <code>integers</code> is out of range; see <a href="Array.html#class-Array-label-Array+Indexes">Array Indexes at <code>Array</code></a>.</p>

<p>With integer range argument <code>integer_range</code> given, returns an array containing each value given by the elements of the range; fills with <code>nil</code> values for range elements larger than the structure:</p>

<pre class="ruby"><span class="ruby-identifier">joe</span>.<span class="ruby-identifier">values_at</span>(<span class="ruby-value">0</span><span class="ruby-operator">..</span><span class="ruby-value">2</span>)
<span class="ruby-comment"># =&gt; [&quot;Joe Smith&quot;, &quot;123 Maple, Anytown NC&quot;, 12345]</span>
<span class="ruby-identifier">joe</span>.<span class="ruby-identifier">values_at</span>(<span class="ruby-value">-3</span><span class="ruby-operator">..</span><span class="ruby-value">-1</span>)
<span class="ruby-comment"># =&gt; [&quot;Joe Smith&quot;, &quot;123 Maple, Anytown NC&quot;, 12345]</span>
<span class="ruby-identifier">joe</span>.<span class="ruby-identifier">values_at</span>(<span class="ruby-value">1</span><span class="ruby-operator">..</span><span class="ruby-value">4</span>) <span class="ruby-comment"># =&gt; [&quot;123 Maple, Anytown NC&quot;, 12345, nil, nil]</span>
</pre>

<p>Raises <a href="RangeError.html"><code>RangeError</code></a> if any element of the range is negative and out of range; see <a href="Array.html#class-Array-label-Array+Indexes">Array Indexes at <code>Array</code></a>.</p>

                              <div class="method-source-code" id="values_at-source">
            <pre>static VALUE
rb_struct_values_at(int argc, VALUE *argv, VALUE s)
{
    return rb_get_values_at(s, RSTRUCT_LEN(s), argc, argv, struct_entry);
}</pre>
                              </div>
                            </div>


                          </div>

                          </section>

              </section>
              </main>



            </div>  <!--  class='wrapper hdiv' -->


<footer id="validator-badges" role="contentinfo">
<p><a href="https://validator.w3.org/check/referer">Validate</a></p>
<p>Generated by <a href="https://ruby.github.io/rdoc/">RDoc</a> 6.4.0.</p>
<p>Based on <a href="https://github.com/ged/darkfish/">Darkfish</a> by <a href="http://deveiate.org">Michael Granger</a>.</p>

  
    <p><p><a href="https://ruby-doc.org">Ruby-doc.org</a> is provided by <a href="https://jamesbritt.com">James Britt</a> and <a href="https://neurogami.com">Neurogami</a>. </p><p><a href="https://jamesbritt.bandcamp.com/">Hack your world.  Feed your head.  Live curious</a>.</p>
</p>
  
  </footer>

<script type="text/javascript">


  let ads  = $("#carbonads-container").children().detach();


  function swapMode() {
    var cookieName = 'darkmode';
    var cssDarkmode = Cookies.get(cookieName);
    console.log("***** swapMode! " + cssDarkmode + " *****");


    if (cssDarkmode == "true") {
      console.log("We have dark mode, set the css to light ...");
      $('#rdoccss').attr("href", defaultModeCssHref);
      $('#cssSelect').text("Dark mode");
      cssDarkmode = "false";
      console.log("swapMode! Now set cookie to " + cssDarkmode);
      Cookies.set(cookieName, cssDarkmode);

    } else {
      console.log("We not have dark mode, set the css to dark ...");
      $('#rdoccss').attr("href", darkModeCsseHref);
      $('#cssSelect').text("Light mode");
      cssDarkmode = "true";
      console.log("swapMode! Now set cookie to " + cssDarkmode);
      Cookies.set(cookieName, cssDarkmode);

    }

    console.log("  --------------- ");
  }


const vueCssApp = new Vue({
el: '#menubar',
data: {
isDark: false
},
methods: {
toggleClass: function(event){
this.isDark = !this.isDark;
}
}
})

const vueApp = new Vue({
el: '#vapp',
data: { 
isOpen: true
},

mounted() {
this.handleResize();
this.manage_mob_classes();
window.addEventListener('resize', this.handleResize)
//this.isOpen !=  (/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent));
},
destroyed() {
window.removeEventListener('resize', this.handleResize)
},
created() {
//manage_mob_classes();
},

methods : {
isMobile() {
  return (/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent));
},

  handleResize() {
    if (!this.isMobile()) {
      this.isOpen = window.innerWidth > 800;
    }
  },

  manage_mob_classes() {
    if (/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)) {
      $("nav").addClass("mob_nav");
      $("main").addClass("mob_main");
      $("#extraz").addClass("mob_extraz");
      $("#carbonads-container").addClass("mob_carbonads-container");
      this.isOpen  = false;
    } else {
      $("nav").removeClass("mob_nav") 
        $("main").removeClass("mob_main");
      $("#extraz").removeClass("mob_extraz");
      $("#carbonads-container").removeClass("mob_carbonads-container");
      this.isOpen  = true;
    }
  },

  toggleNav() {
    this.isOpen =! this.isOpen ;
    // alert("Toggle nav!");
    console.log("toggleNav() click: " + this.isOpen );
  }
}
})

$("#carbonads-container").append(ads);


$(function() {

    var darkmode = Cookies.get("darkmode");
    console.log("Document ready: " + darkmode);

    if ( darkmode  == "true" ) {
      $('#cssSelect').text("Light mode");
    } else {
      $('#cssSelect').text("Dark mode");
     }

    $('body').css('display','block');
    });

</script>

    
  </body> 
</html>

